package com.example.jfinal;

import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * Created by mengdexuan on 2017/3/7 15:31.
 * 利用 JFinal 提供 ActiveRecordPlugin，方便对数据库的查询操作，增删改用 JPA，方便事务处理
 * */
@Component
public class JfinalRecord {

	private static Logger log = LoggerFactory.getLogger(JfinalRecord.class);

	public JfinalRecord(){
		PropKit.use("application.properties");

		String url = PropKit.get("spring.datasource.url");
		String userName = PropKit.get("spring.datasource.username");
		String password = PropKit.get("spring.datasource.password");


		log.info("数据库信息：");
		log.info("url --> "+url);
		log.info("userName --> "+userName);
		log.info("password --> "+password);

		DruidPlugin dp = new DruidPlugin(url,userName,password);
		ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
		dp.start();
		arp.setShowSql(true);
		arp.start();
	}
}
